﻿<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
		<meta name="apple-mobile-web-app-title" content="思路广惠">
		<title>新增推广</title>
		<meta content="telephone=no" name="format-detection" />
		<link rel="stylesheet" type="text/css" href="../../src/css/base.css?1.0" />
	</head>

	<body class="body-bg">
		<header class="header clearfix">
			<a href="javascript: history.go(-1)" id="backs" class="head-le"><i class="iconfont icon-fanhui i2m"></i></a>
			<h1 class="header-txt">新增</h1>
		</header>
		<section class="top1rem"> 
			<ul id="promote" class="setup-u">
				 
			</ul>
			<div class="own-save">
				<button class="own-save-btn" id="recommend" type="button">
            		确认推荐
            	</button>
			</div>

		</section>
		<script type="text/html" class="promote">
				<li class="flexs-al forpwd setup-btm">  
					<input type="text" placeholder="新会员手机号" class="memadd forpwd-inp" />
				</li>
				<li class="flexs-al forpwd"> 
					<input type="text" placeholder="新会员姓名" class="memadd forpwd-inp" />
				</li> 
		</script>
		<script type="text/html" class="promote">
		 		<li class="address-inp setup-btm">
					<span> 商家账号： </span> <input type="email" placeholder="邮箱" class="addRess bussiness" />
				</li>
				<li class="address-inp setup-btm">
					<span> 商家名称： </span> <input type="text" placeholder="商家公司名称" class="addRess bussiness" />
				</li>
				<li class="pad1rem setup-btm flexs-bw">
					<select class="address-sel bussiness">
						<option value="0">请选择行业</option>
					</select>
					<i class="iconfont icon-gengduo"></i>
				</li> 
				<li class="address-inp setup-btm">
					<span> 机构代码： </span> <input type="text" placeholder="组织机构代码" class="addRess bussiness" />
				</li> 
				<li class="address-inp setup-btm">
					<span> 联系人： </span> <input type="text" placeholder="联系人姓名" class="addRess bussiness" />
				</li>
				<li class="address-inp setup-btm">
					<span> 联系电话： </span> <input type="tel" placeholder="联系人电话" class="addRess bussiness" />
				</li>  
				<li class="pad1rem setup-btm flexs-bw">
					<select id="Province" class="address-sel bussiness">
						<option value="0">请选择省</option>
					</select>
					<i class="iconfont icon-gengduo"></i>
				</li>
				<li class="pad1rem setup-btm flexs-bw">
					<select id="City" class="address-sel bussiness">
						<option value="0">请选择市</option>
					</select>
					<i class="iconfont icon-gengduo"></i>
				</li>
				<li class="pad1rem setup-btm flexs-bw">
					<select id="County" class="address-sel bussiness">
						<option value="0">请选择县</option>
					</select>
					<i class="iconfont icon-gengduo"></i>
				</li>
				<li class="address-inp">
					<span> 详细地址： </span> <input type="text" placeholder="请输入详细地址" class="addRess bussiness" />
				</li> 

			 

		</script>
		<script src="http://apps.bdimg.com/libs/laytpl.js/1.1/laytpl.js"></script>
		<script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
		<script src="//cdn.bootcss.com/layer/3.0.1/mobile/layer.js"></script>
		<script src="../../src/js/all.js" type="text/javascript" charset="utf-8"></script>
		<script>
			var numhref = silks.getByVal("flag");

			switch(numhref) {
				case "0":
					$(".header-txt").html("新增会员");
					$("title").html("新增会员");
					$("#promote").html($(".promote:first").html());
					break;
				case "1":
					$(".header-txt").html("新增商家");
					$("title").html("新增商家");
					$("#promote").html($(".promote:last").html());

					// 行业获取
					$.get(urls + "/BaseSelect/GetIndustry ", function(res) {
						var opt = '<option value="0">请选择行业</option>';
						if(res.Return_ID == 0) {
							for(var i = 0; i < res.Return_Data.length; i++) {
								opt += '<option value=' + res.Return_Data[i].Value + '>' + res.Return_Data[i].Text + '</option>'
							}
						}
						$(".bussiness").eq(2).html(opt);
					});
					// 省份获取
					$.get(urls + "/BaseSelect/GetProvince", function(res) {
						var opt = '<option value="0">请选择省</option>';
						if(res.Return_ID == 0) {
							for(var i = 0; i < res.Return_Data.length; i++) {
								opt += '<option value=' + res.Return_Data[i].Value + '>' + res.Return_Data[i].Text + '</option>'
							}
						}
						$("#Province").html(opt);
					});

					$.get(urls + "/BaseSelect/GetProvince", function(res) {
						var opt = '<option value="0">请选择省</option>';
						if(res.Return_ID == 0) {
							for(var i = 0; i < res.Return_Data.length; i++) {
								opt += '<option value=' + res.Return_Data[i].Value + '>' + res.Return_Data[i].Text + '</option>'
							}
						}
						$("#Province").html(opt);
					});

					$(document).on("change", "#Province", function() {
						var ProvinceID = $(this).find("option:selected").val();
						$.get(urls + "/BaseSelect/GetCity", {
							ProvinceID: ProvinceID
						}, function(res) {
							var opt = '<option value="0">请选择市</option>';
							if(res.Return_ID == 0) {
								for(var i = 0; i < res.Return_Data.length; i++) {
									opt += '<option value=' + res.Return_Data[i].Value + '>' + res.Return_Data[i].Text + '</option>'
								}
							}
							$("#City").html(opt);
							$("#County").html('<option value="0">请选择县</option>');
						});
					});

					$(document).on("change", "#City", function() {
						var CityID = $(this).find("option:selected").val();
						$.get(urls + "/BaseSelect/GetCounty", {
							CityID: CityID
						}, function(res) {
							var opt = '<option value="0">请选择县</option>';
							if(res.Return_ID == 0) {
								for(var i = 0; i < res.Return_Data.length; i++) {
									opt += '<option value=' + res.Return_Data[i].Value + '>' + res.Return_Data[i].Text + '</option>'
								}
							}
							$("#County").html(opt);
						});
					});

					break;
				default:
					//没有其他条件
					break;
			}

			$("#recommend").click(function() {
				if(numhref == 0) {
					var $memadd = $(".memadd");
					if(!/^1\d{10}$/.test($memadd.eq(0).val())) {
						layers("号码输入有误");
					} else if($memadd.eq(1).val() == "") {
						layers("推荐会员名不能为空");
					} else {
						$.post(urls + "/WorkIntro/IntroMembers", {
							MembersID: MembersID,
							MembersName: $memadd.eq(1).val(),
							MembersPhone: $memadd.eq(0).val(),
							AppID: AppID,
							Token: Token
						}, function(res) {
							console.log(res)
							layers(res.Return_Mess);
						})
					}
				}
				if(numhref == 1) {
					var $mi = $(".bussiness");
					var $va = function(n) {
						return $mi.eq(n).val();
					}
					if(!/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test( $va(0) )) {
						layers("请输入正确邮箱");
					} else if(!$va(1)) {
						layers("请输入商家名称");
					} else if($va(2) == "0") {
						layers("请选择行业");
					} else if(!/^\d+$/.test($va(3))) {
						layers("输入错误，机构代码为数字");
					} else if(!$va(4)) {
						layers("请输入联系人");
					} else if(!/^1\d{10}$/.test($va(5))) {
						layers("请输入正确号码");
					} else if($va(6) == "0") {
						layers("请选择省");
					} else if($va(7) == "0") {
						layers("请选择市");
					} else if($va(8) == "0") {
						layers("请选择县");
					} else if(!$va(9)) {
						layers("请输入详细地址");
					} else {

						$.post(urls + "/WorkIntro/IntroMembers", {
							MembersID: MembersID,
							BusinessID: $va(0),
							BusinessName: $va(1),
							IndustryID: $va(2),
							CardID: $va(3),
							Contacts: $va(4),
							Phone: $va(5),
							Email: $va(0),
							ProvinceID: $va(6),
							CityID: $va(7),
							CountyID: $va(8),
							Address: $va(9),
							AppID: AppID,
							Token: Token
						}, function(res) {
							console.log(res)
							layers(res.Return_Mess);
						})

					}

				}
			})
		</script>
	</body>

</html>